<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>题库</title>
  <link rel="stylesheet" type="text/css" href="<%=path %>/style/easyui.css">
  <link rel="stylesheet" type="text/css" href="<%=path %>/style/icon.css">
  <link rel="stylesheet" type="text/css" href="<%=path %>/style/neweasyui/themes/gray/panel.css">
  <link rel="stylesheet" type="text/css" href="<%=path %>/style/neweasyui/themes/gray/window.css">
  <script type="text/javascript" src="<%=path %>/script/1.11.1.js"></script>
  <script type="text/javascript" src="<%=path %>/script/jquery.easyui.min.js"></script>
  <script type="text/javascript" src="<%=path %>/script/easyui-lang-zh_CN.js"></script>
  <script type="text/javascript" src="<%=path %>/script/dateFormat.js"></script>
  <script type="text/javascript" src="<%=path %>/script/datagrid-bufferview.js"></script>
  <script type="text/javascript" src="<%=path %>/script/common.js"></script>
  <style type="text/css">
    #fm{
      margin:0;
      padding:10px 30px;
    }
    .ftitle{
      font-size:14px;
      font-weight:bold;
      padding:5px 0;
      margin-bottom:10px;
      border-bottom:1px solid #ccc;
    }
    .fitem{
      margin-bottom:17px;
    }
    .fitem label{
      display:inline-block;
      width:80px;
    }
    .fitem input{
      width:230px;
    }
  </style>
</head>
<body>
<table id="tt" title="class" style="width:auto;height:800px">
</table>
<div id="toolbar" style="padding:5px;height:auto">
  <div>
    <!-- 搜索条件结束 -->
    <a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-add" onclick="newClass()">添加</a>&nbsp;
    <a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-edit" onclick="editClass()">修改</a>&nbsp;
    <a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-remove" onclick="deleteClass()">删除</a>&nbsp;&nbsp;

  </div>
</div>



<!-- 添加/编辑框 开始-->
<div id="dlg" class="easyui-dialog"
     style="width: 600px; height: 550px; padding: 10px 20px" closed="true"
     buttons="#dlg-buttons">
  <div class="ftitle">Class信息</div>
  <form id="fm" method="post"  validate enctype="multipart/form-data">
    <input type="hidden" name="id" id="cls_id" />

    <div class="fitem">
      <label>名称:</label>
      <input  class="easyui-textbox" name="name" id="cls_name" required value=""/>
    </div>

    <div class="fitem">
      <label>描述:</label>
      <textarea style="overflow-y:visible;border:1;width:70%;height:60px;" name="desc"></textarea>
    </div>
    <div class="fitem">
      <label>是否推荐:</label>
      <select class="easyui-combobox" name="recommended" id="recommended" required panelHeight="auto">
      	<option value="0">不推荐</option>
      	<option value="1">推荐</option>
      </select>
    </div>
    <div class="fitem">
      <label>出现频率:</label>
      <input  class="easyui-textbox" name="frequency" id="frequency" value=""   />
    </div>
    <div class="fitem">
      <label>图片路径:</label>
      <input  type="file" name="file" id="file" value=""   />
    </div>
    <div class="fitem">
      <label>排序:</label>
      <input  class="easyui-textbox" name="seqNum" id="seqNum"  value=""  required />
    </div>
    <div class="fitem">
      <label>课程类型:</label>
      <input  class="easyui-textbox" name="type" id="type" value=""  required />
       <font color="red">*|&nbsp;&nbsp;此处设为 0,只有机经设为 1 </font>
    </div>
  </form>
  <div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveOrUpdateClass()" style="width: 90px">Save</a> 
    <a href="javascript:void(0)" class="easyui-linkbutton"  iconCls="icon-cancel"  onclick="closeDialog()"  style="width: 90px">Cancel</a>
  </div>
</div>

</body>
<script type="text/javascript">
  var class_id,course_id,gate_id;
  $.ajaxSetup({cache:false});
  $(function(){
    $('#tt').datagrid({
      url:'<%=basePath %>service/class/sys/list',
      method:'get',
      singleSelect:true,toolbar:'#toolbar',remoteSort:false,pageSize:50,nowrap:false,
      fitColumns:true,rownumbers:true,
      columns:[[
        {field:'id',title:'ID',sortable:true,width:20,hidden:true},
        {field:'name',title:'标题',sortable:true,width:60},
        {field:'desc',title:'描述',sortable:true,width:80},
        {field:'recommended',title:'推荐',sortable:true,width:80},
        {field:'frequency',title:'出现频率',sortable:true,width:50,
          formatter: function(value,row,index){
            var str="" ;
            return value+"%";
          }
        },
        {field:'imgUrl',title:'图片链接',sortable:true,width:100},
        {field:'seqNum',title:'排序',sortable:true,width:100},
        {field:'type',title:'课程类型',sortable:true,width:100}
      ]],
      
    });
  });

  //关闭弹出框
  function closeDialog(){
    $('#dlg').dialog('close') ;
  }

  //添加class
  function newClass(){
    $('#dlg').dialog('open').dialog('setTitle','添加class');
    $('#fm').form('clear');
    url = '<%=basePath%>service/class/sys/add';
  }

  function editClass(){
	  var row = $('#tt').datagrid('getSelected');
      	if(row.type == 1){
      		$.messager.show({
                  title : '提示',
                  msg : '不能在此处编辑机经!<br/> 只能在机经预测中编辑'
                });
      		return;
      	}
    url = '<%=basePath%>service/class/sys/edit';
    var row = $('#tt').datagrid('getSelected');
    if (row){
      $("#cls_id").val(row.id);
      $('#dlg').dialog('open').dialog('setTitle','编辑class');
      $('#fm').form('load',row);
    }
  }


  function deleteClass(){

    var row = $('#tt').datagrid('getSelected');
    if (row){
      $.messager.confirm('提示','确定要删除这个class吗？',function(r){
        if (r){
          $.post('<%=basePath%>service/class/sys/remove',{id:row.id,type:row.type},function(result){
        	if(result.status == "false"){
        		$.messager.show({
                    title : '提示',
                    msg : '不能删除机经!'
                  });
        		return;
        	}
            $('#tt').datagrid('reload');    // reload the data
          },'json');
        }
      });
    }
  }


  //添加或修改class
  function saveOrUpdateClass(){

    $('#fm').form('submit', {
      url : url,
      onSubmit : function() {
        return $(this).form('validate');
      },
      success : function(result) {

        if (result.status) {
          $.messager.show({
            title : 'Error',
            msg : '服务器出错，请稍后再试'
          });
        } else {
          $('#dlg').dialog('close'); // close the dialog
          $('#tt').datagrid('reload'); // reload the data
        }
      }
    });
  }







</script>
</html>
